package syschannel_connector

import (
	"go-iot-gateway/internal/channel"
	channel_define "go-iot-gateway/internal/channel/define"
	conf_table_define "go-iot-gateway/internal/conf_table/define"
)

func NewSysChannel(channelConfig conf_table_define.ChannelInfo) (channel_define.ConnectChannel, error) {
	manager := channel.Manager()

	chl := &SysChannel{}
	chl.channelManager = manager
	chl.ChannelInfo = channel_define.ChannelInfo{}
	chl.isClosed = false
	chl.ChannelInfo.ChlId = channelConfig.Chl_id
	chl.ChannelInfo.Name = channelConfig.Chl_name
	chl.ChannelInfo.Addr = (channelConfig.Chl_addr)
	chl.ChannelInfo.Desc = channelConfig.Chl_desc
	chl.ChannelInfo.Protocol = channelConfig.Chl_protocol
	chl.ChannelInfo.SetStatus(channel_define.CONNECT_STATUS_CREATE, "已创建")
	chl.ChannelInfo.ChannelType = channelConfig.Chl_type
	chl.ChannelInfo.ProtocolType = channelConfig.Protocol_type
	chl.ChannelInfo.Frequency = channelConfig.Chl_colt_freq
	chl.ChannelInfo.WaitTime = channelConfig.Chl_wait_time

	return chl, nil
}
